import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_first/widget/custom_scroll.dart';

class DialogDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Dialog组件'),
        centerTitle: true,
      ),
      body: Column(
        children: <Widget>[
          Padding(
            padding: EdgeInsets.only(top: 30, left: 20, right: 20, bottom: 15),
            child: Row(
              children: <Widget>[
                Expanded(
                    child: Builder(
                        builder: (ctx) => ElevatedButton(
                            child: Text('关于'),
                            style: ButtonStyle(
                                padding: MaterialStateProperty.all(EdgeInsets.symmetric(vertical: 15))
                            ),
                            onPressed: () {
                              showAboutDialog(
                                  context: ctx,
                                  applicationIcon: ClipOval(
                                    child: Image.asset(
                                      'images/card03.png',
                                      width: 60,
                                      height: 60,
                                      fit: BoxFit.cover,
                                    ),
                                  ),
                                  applicationName: 'Flutter测试',
                                  applicationVersion: 'v1.0.0',
                                  applicationLegalese: 'xinnuo@copyright 2020',
                                  children: <Widget>[
                                    Container(
                                      height: 30,
                                      color: Colors.red,
                                    ),
                                    Container(
                                      height: 30,
                                      color: Colors.blue,
                                    ),
                                    Container(
                                      height: 30,
                                      color: Colors.green,
                                    ),
                                  ]);
                            })))
              ],
            ),
          ),
          Padding(
            padding: EdgeInsets.symmetric(vertical: 15, horizontal: 20),
            child: Row(
              children: <Widget>[
                Expanded(
                    child: Builder(
                        builder: (ctx) => ElevatedButton(
                            child: Text('提示'),
                            style: ButtonStyle(
                                padding: MaterialStateProperty.all(EdgeInsets.symmetric(vertical: 15))
                            ),
                            onPressed: () {
                              showDialog(
                                context: ctx,
                                barrierDismissible: false,
                                builder: (context) => AlertDialog(
                                  title: Text('温馨提示'),
                                  content: Text('确定要显示吗？'),
                                  actions: <Widget>[
                                    TextButton(
                                        onPressed: () {
                                          Navigator.of(context).pop('cancel');
                                        },
                                        child: Text('取消')),
                                    TextButton(
                                        onPressed: () {
                                          Navigator.of(context).pop('ok');
                                          Navigator.of(context).pop('close');
                                        },
                                        child: Text('确定')),
                                  ],
                                ),
                              );
                            })))
              ],
            ),
          ),
          Padding(
            padding: EdgeInsets.symmetric(vertical: 15, horizontal: 20),
            child: Row(
              children: <Widget>[
                Expanded(
                    child: Builder(
                        builder: (ctx) => ElevatedButton(
                            child: Text('IOS提示'),
                            style: ButtonStyle(
                                padding: MaterialStateProperty.all(EdgeInsets.symmetric(vertical: 15))
                            ),
                            onPressed: () {
                              showCupertinoDialog(
                                context: ctx,
                                builder: (context) => CupertinoAlertDialog(
                                  title: Text('温馨提示'),
                                  content: Text('确定要显示吗？'),
                                  actions: <Widget>[
                                    CupertinoDialogAction(
                                      child: Text('取消'),
                                      onPressed: () {
                                        Navigator.of(context).pop('cancel');
                                      },
                                    ),
                                    CupertinoDialogAction(
                                      child: Text('确定'),
                                      onPressed: () {
                                        Navigator.of(context).pop('ok');
                                        Navigator.of(context).push(
                                            MaterialPageRoute(
                                                builder: (context) => CustomScrollViewDemo()
                                            )
                                        );
                                      },
                                    ),
                                  ],
                                ),
                              );
                            }
                        )
                    )
                )
              ],
            ),
          ),
          Padding(
            padding: EdgeInsets.only(top: 15, left: 20, right: 20),
            child: Row(
              children: <Widget>[
                Expanded(
                    child: Builder(
                        builder: (ctx) => ElevatedButton(
                            child: Text('选择日期'),
                            style: ElevatedButton.styleFrom(
                              padding: EdgeInsets.symmetric(vertical: 15),
                            ),
                            onPressed: () {
                              showDatePicker(
                                  context: ctx,
                                  initialDate: DateTime.now(),
                                  firstDate: DateTime(1900),
                                  lastDate: DateTime(2200));
                              }
                            )
                    )
                )
              ],
            ),
          ),
        ],
      ),
    );
  }
}
